<template>
  <div class="goods-hot">
    <h3>{{types[type]}}</h3>
    <div v-if="goodsList">
      <GoodsItem v-for="item in goodsList" :key="item.id" :goods="item" />
    </div>
  </div>
</template>

<script>
import GoodsItem from '@/views/category/components/goods-item.vue'
import {findGoodsHot} from '@/api/product'
import { reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  components:{
    GoodsItem
  },
  props:{
    type:{
      type:Number,
      default:1
    }
  },
  setup(props) {
    const types = reactive({1:'24小时热销版',2:'周热销榜',3:'总热销榜'})
    const route = useRoute()
    let goodsList = ref([])
    //发起网络请求
    findGoodsHot({id:route.params.id,type:props.type}).then(data => {
      goodsList.value = data.result
    }) 
    
    return {
      types,
      goodsList
    }
  }
}
</script>

<style lang="less" scoped>
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  ::v-deep .goods-item {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;

    img {
      width: 200px;
      height: 200px;
    }

    p {
      margin: 0 10px;
    }

    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>